#!/bin/bash

SATMC_HOME=$(cd `dirname $(readlink -e $0)` && pwd) #recursively resolves symbolic links and resolves relative paths
export SP_PATH=$SATMC_HOME/lib/sicstus-4.2.0

CMD_LINE="$SATMC_HOME/satmc-core"
TMP_OUT=`mktemp`

trap 'rm -f $TMP_OUT; exit' EXIT


CMD_LINE="$CMD_LINE $@" #--aslanof
$CMD_LINE |tee $TMP_OUT

LTLcheck=`cat $TMP_OUT | grep "\-\-enc=ltl-gp" | wc -l`

if [ "$LTLcheck" -eq 1 ]; then
    echo % SATMC is going to be automatically run with --enc=ltl-gp.
    CMD_LINE="$CMD_LINE --enc=ltl-gp"
    $CMD_LINE |tee $TMP_OUT
fi

exit 0
trap 'kill $(jobs -p)' EXIT
